<?php
/*/**
 * 功能说明：奖品
 * 参数说明：
 * 返回值：
 * 备注说明：
 * 作者：Administrator
 * 最后一次修改时间:2017/5/13 17:16
 */

namespace logic\luckydraw;

use logic\LogicException;


class Prize
{
	//ID
	public $id = null;

	//权重
	public $weight = null;

	//奖品名
	public $name = null;

	//权重范围区间起始值
	protected $start = 0;

	//权重范围区间结束值
	protected $end = 0;

	public function __construct( $id , $weight , $name = null )
	{
		if ( !$id ) {
			throw new LogicException( 4 );
		}

		$this -> id = $id;
		$this -> weight = $weight ? $weight : 0;
		$this -> name = $name ? $name : '随机奖品' . $id;
	}

	//id

	public function getId()
	{
		return $this -> id;
	}

	//权重
	public function getWeight()
	{
		return $this -> weight;
	}

	//设置权重范围区间
	public function setRange( $start , $end )
	{
		$this -> start = $start;
		$this -> end = $end;
	}

	//判断随机数是否在权重范围区间
	public function inRange( $num )
	{
		//echo "奖品id：{$this->id},范围:{$this->start}----{$this->end}";
		return ( $num >= $this -> start ) && ( $num <= $this -> end );
	}

}
